home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší České Hry 2007 / Nejlepší české hry 2007.iso / hry / Becherovka CHAMPIONSHIP / main.cs < prev    next >
Text File  |  2006-09-18  |  8KB  |  298 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. $defaultGame = "championship";
  7. $displayHelp = false;
  8.  
  9.  
  10. //-----------------------------------------------------------------------------
  11. // Support functions used to manage the mod string
  12.  
  13. function pushFront(%list, %token, %delim)
  14. {
  15.    if (%list !$= "")
  16.       return %token @ %delim @ %list;
  17.    return %token;
  18. }
  19.  
  20. function pushBack(%list, %token, %delim)
  21. {
  22.    if (%list !$= "")
  23.       return %list @ %delim @ %token;
  24.    return %token;
  25. }
  26.  
  27. function popFront(%list, %delim)
  28. {
  29.    return nextToken(%list, unused, %delim);
  30. }
  31.  
  32.  
  33. //------------------------------------------------------------------------------
  34. // Process command line arguments
  35.  
  36. // Run the Torque Creator mod by default, it's needed for editors.
  37.  
  38.  
  39. $isDedicated = false;
  40. $modcount = 2;
  41. $userMods = "creator;" @ $defaultGame;
  42.  
  43. for ($i = 1; $i < $Game::argc ; $i++)
  44. {
  45.    $arg = $Game::argv[$i];
  46.    $nextArg = $Game::argv[$i+1];
  47.    $hasNextArg = $Game::argc - $i > 1;
  48.    $logModeSpecified = false;
  49.  
  50.    // Check for dedicated run
  51.    if( stricmp($arg,"-dedicated") == 0  )
  52.    {
  53.        $userMods = $defaultGame;
  54.        $modcount = 1;
  55.        $isDedicated = true;
  56.    }
  57.    
  58.    switch$ ($arg)
  59.    {
  60.       //--------------------
  61.       case "-log":
  62.          $argUsed[$i]++;
  63.          if ($hasNextArg)
  64.          {
  65.             // Turn on console logging
  66.             if ($nextArg != 0)
  67.             {
  68.                // Dump existing console to logfile first.
  69.                $nextArg += 4;
  70.             }
  71.             setLogMode($nextArg);
  72.             $logModeSpecified = true;
  73.             $argUsed[$i+1]++;
  74.             $i++;
  75.          }
  76.          else
  77.             error("Error: Missing Command Line argument. Usage: -log <Mode: 0,1,2>");
  78.  
  79.       //--------------------
  80.       case "-mod":
  81.          $argUsed[$i]++;
  82.          if ($hasNextArg)
  83.          {
  84.             // Append the mod to the end of the current list
  85.             $userMods = strreplace($userMods, $nextArg, "");
  86.             $userMods = pushFront($userMods, $nextArg, ";");
  87.             $argUsed[$i+1]++;
  88.             $i++;
  89.             $modcount++;
  90.          }
  91.          else
  92.             error("Error: Missing Command Line argument. Usage: -mod <mod_name>");
  93.             
  94.       //--------------------
  95.       case "-game":
  96.          $argUsed[$i]++;
  97.          if ($hasNextArg)
  98.          {
  99.             // Set the selected mod and creator for editor stuff.
  100.         if( $isDedicated )
  101.         {
  102.         $userMods = $nextArg;
  103.         $modcount = 1;
  104.         } else {
  105.         $userMods = "creator;" @ $nextArg;
  106.         $modcount = 2;
  107.         }
  108.             $argUsed[$i+1]++;
  109.             $i++;
  110.         error($userMods);
  111.          }
  112.          else
  113.             error("Error: Missing Command Line argument. Usage: -game <game_name>");
  114.             
  115.       //--------------------
  116.       case "-show":
  117.          // A useful shortcut for -mod show
  118.          $userMods = strreplace($userMods, "show", "");
  119.          $userMods = pushFront($userMods, "show", ";");
  120.          $argUsed[$i]++;
  121.          $modcount++;
  122.  
  123.       //--------------------
  124.       case "-console":
  125.          enableWinConsole(true);
  126.          $argUsed[$i]++;
  127.  
  128.       //--------------------
  129.       case "-jSave":
  130.          $argUsed[$i]++;
  131.          if ($hasNextArg)
  132.          {
  133.             echo("Saving event log to journal: " @ $nextArg);
  134.             saveJournal($nextArg);
  135.             $argUsed[$i+1]++;
  136.             $i++;
  137.          }
  138.          else
  139.             error("Error: Missing Command Line argument. Usage: -jSave <journal_name>");
  140.  
  141.       //--------------------
  142.       case "-jPlay":
  143.          $argUsed[$i]++;
  144.          if ($hasNextArg)
  145.          {
  146.             playJournal($nextArg,false);
  147.             $argUsed[$i+1]++;
  148.             $i++;
  149.          }
  150.          else
  151.             error("Error: Missing Command Line argument. Usage: -jPlay <journal_name>");
  152.  
  153.       //--------------------
  154.       case "-jDebug":
  155.          $argUsed[$i]++;
  156.          if ($hasNextArg)
  157.          {
  158.             playJournal($nextArg,true);
  159.             $argUsed[$i+1]++;
  160.             $i++;
  161.          }
  162.          else
  163.             error("Error: Missing Command Line argument. Usage: -jDebug <journal_name>");
  164.  
  165.       //-------------------
  166.       case "-help":
  167.          $displayHelp = true;
  168.          $argUsed[$i]++;
  169.  
  170.       //-------------------
  171.       default:
  172.          $argUsed[$i]++;
  173.          if($userMods $= "")
  174.             $userMods = $arg;
  175.    }
  176. }
  177.  
  178. if($modcount == 0) {
  179.       $userMods = $defaultGame;
  180.       $modcount = 1;
  181. }
  182.  
  183. //-----------------------------------------------------------------------------
  184. // The displayHelp, onStart, onExit and parseArgs function are overriden
  185. // by mod packages to get hooked into initialization and cleanup. 
  186.  
  187. function onStart()
  188. {
  189.    // Default startup function
  190. }
  191.  
  192. function onExit()
  193. {
  194.    // OnExit is called directly from C++ code, whereas onStart is
  195.    // invoked at the end of this file.
  196. }
  197.  
  198. function parseArgs()
  199. {
  200.    // Here for mod override, the arguments have already
  201.    // been parsed.
  202. }   
  203.  
  204. package Help {
  205.    function onExit() {
  206.       // Override onExit when displaying help
  207.    }
  208. };
  209.  
  210. function displayHelp() {
  211.    activatePackage(Help);
  212.  
  213.       // Notes on logmode: console logging is written to console.log.
  214.       // -log 0 disables console logging.
  215.       // -log 1 appends to existing logfile; it also closes the file
  216.       // (flushing the write buffer) after every write.
  217.       // -log 2 overwrites any existing logfile; it also only closes
  218.       // the logfile when the application shuts down.  (default)
  219.  
  220.    error(
  221.       "Torque Demo command line options:\n"@
  222.       "  -log <logmode>         Logging behavior; see main.cs comments for details\n"@
  223.       "  -game <game_name>      Reset list of mods to only contain <game_name>\n"@
  224.       "  <game_name>            Works like the -game argument\n"@
  225.       "  -mod <mod_name>        Add <mod_name> to list of mods\n"@
  226.       "  -console               Open a separate console\n"@
  227.       "  -show <shape>          Launch the TS show tool\n"@
  228.       "  -jSave  <file_name>    Record a journal\n"@
  229.       "  -jPlay  <file_name>    Play back a journal\n"@
  230.       "  -jDebug <file_name>    Play back a journal and issue an int3 at the end\n"@
  231.       "  -help                  Display this help message\n"
  232.    );
  233. }
  234.  
  235.  
  236. //--------------------------------------------------------------------------
  237.  
  238. // Default to a new logfile each session.
  239. if (!$logModeSpecified) {
  240.    setLogMode(6);
  241. }
  242.  
  243. // Set the mod path which dictates which directories will be visible
  244. // to the scripts and the resource engine.
  245. setModPaths($userMods);
  246.  
  247. // Get the first mod on the list, which will be the last to be applied... this
  248. // does not modify the list.
  249. nextToken($userMods, currentMod, ";");
  250.  
  251. // Execute startup scripts for each mod, starting at base and working up
  252. function loadDir(%dir)
  253. {
  254.    setModPaths(pushback($userMods, %dir, ";"));
  255.    exec(%dir @ "/main.cs");
  256. }
  257.  
  258. echo("--------- Loading MODS ---------");
  259. function loadMods(%modPath)
  260. {
  261.    %modPath = nextToken(%modPath, token, ";");
  262.    if (%modPath !$= "")
  263.       loadMods(%modPath);
  264.  
  265.    if(exec(%token @ "/main.cs") != true){
  266.       error("Error: Unable to find specified mod: " @ %token );
  267.       $modcount--;
  268.    }
  269. }
  270. loadMods($userMods);
  271. echo("");
  272.  
  273. if($modcount == 0) {
  274.    enableWinConsole(true);
  275.    error("Error: Unable to load any specified mods");
  276.    quit();  
  277. }
  278. // Parse the command line arguments
  279. echo("--------- Parsing Arguments ---------");
  280. parseArgs();
  281.  
  282. // Either display the help message or startup the app.
  283. if ($displayHelp) {
  284.    enableWinConsole(true);
  285.    displayHelp();
  286.    quit();
  287. }
  288. else {
  289.    onStart();
  290.    echo("Engine initialized...");
  291. }
  292.  
  293. // Display an error message for unused arguments
  294. for ($i = 1; $i < $Game::argc; $i++)  {
  295.    if (!$argUsed[$i])
  296.       error("Error: Unknown command line argument: " @ $Game::argv[$i]);
  297. }
  298.